package com.music.service.impl;

import com.music.dao.UserLetterMapper;
import com.music.entity.UserLetter;
import com.music.service.UserLetterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class UserLetterServiceImpl implements UserLetterService {
    @Autowired
    private UserLetterMapper userLetterMapper;

    @Override
    public List<UserLetter> findByUserId(String userId, String letter_user_id) {
        return userLetterMapper.findByUserId(userId,letter_user_id);
    }

    @Override
    public int add(UserLetter userLetter) {
        LocalDateTime localDateTime=LocalDateTime.now();
        String id=UUID.randomUUID().toString().replaceAll("-","");
        userLetter.setLetter_time(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        userLetter.setUserLetterId(id);
        return userLetterMapper.add(userLetter);
    }
}
